package net.pinnoocle.playweb.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.pinnoocle.playcommon.aop.PassToken;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.web.wx.FastRegisterApp;
import net.pinnoocle.playservice.service.CommonService;
import net.pinnoocle.playservice.service.impl.RegisterWechatServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ye
 * @Description
 * @create 2021-11-17 9:15
 */
@RestController
@RequestMapping("/wechat")
@Api(tags = "小程序注册相关")
@Slf4j
public class WechatController {

    @Autowired
    RegisterWechatServiceImpl registerWechatService;
    @Autowired
    CommonService commonService;

    @PostMapping("fastRegisterWechat")
    @ApiOperation("快速注册小程序")
    public BaseResult<String> fastRegisterWechat(@Validated @RequestBody FastRegisterApp app){
        boolean result = registerWechatService.fastRegisterWechat(app);
        if(result){
            return new BaseResult<String>().success("申请成功，请耐心等待审核");
        }
        return new BaseResult<String>().error("申请失败");
    }

    @PostMapping("/uploadHeadImage")
    @ApiOperation("上传小程序头像")
    public BaseResult<String> uploadHeadImage(@RequestParam("file") MultipartFile file){
        return new BaseResult<String>().ok(commonService.uploadFileToLocal(file));
    }
}
